 package net.ruixin.web.struts2.plugins;

 import com.google.gson.Gson;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionInvocation;
 import com.opensymphony.xwork2.util.ValueStack;
 import java.io.PrintWriter;
 import javax.servlet.http.HttpServletResponse;
 import org.apache.struts2.dispatcher.StrutsResultSupport;

 public class AjaxDataResultType extends StrutsResultSupport
 {
   private static final long serialVersionUID = 1L;
   private String contentTypeName;
   private String stringName = "";

   private String response = "ok";
   private String message = "";
   private String json = "";
   private String data = "";
   private String next = "";

   public AjaxDataResultType()
   {
   }

   public AjaxDataResultType(String location) {
     super(location);
   }

   protected void doExecute(String finalLocation, ActionInvocation invocation)
     throws Exception
   {
     HttpServletResponse httpResponse = (HttpServletResponse)invocation.getInvocationContext().get("com.opensymphony.xwork2.dispatcher.HttpServletResponse");
     httpResponse.setHeader("Pragma", "No-cache");
     httpResponse.setHeader("Cache-Control", "no-cache");
     httpResponse.setDateHeader("Expires", 0L);
     String contentType = conditionalParse(this.contentTypeName, invocation);
     if (contentType == null) {
       contentType = "text/json; charset=UTF-8";
     }
     httpResponse.setContentType(contentType);

     PrintWriter writer = httpResponse.getWriter();

     String msg = conditionalParse(this.message, invocation);
     String newNext = conditionalParse(this.next, invocation);

     String jsonData = conditionalParse(this.json, invocation);
     if (!this.data.isEmpty()) {
       Gson gs = new Gson();
       Object dataObject = invocation.getStack().findValue(this.data);
       jsonData = gs.toJson(dataObject);
     }

     if (jsonData.isEmpty()) {
       jsonData = "{}";
     }

     String resultText = "{\"response\":\"" + this.response + "\",\"data\":" + jsonData + ",\"message\":\"" + msg + "\",\"next\":\"" + newNext + "\"}";

     writer.println(resultText);
     writer.flush();
     writer.close();
   }

   public String getContentTypeName() {
     return this.contentTypeName;
   }
   public void setContentTypeName(String contentTypeName) {
     this.contentTypeName = contentTypeName;
   }
   public String getStringName() {
     return this.stringName;
   }
   public void setStringName(String stringName) {
     this.stringName = stringName;
   }

   public String getResponse() {
     return this.response;
   }

   public void setResponse(String response) {
     this.response = response;
   }

   public String getMessage() {
     return this.message;
   }

   public void setMessage(String message) {
     this.message = message;
   }

   public String getJson() {
     return this.json;
   }

   public void setJson(String json) {
     this.json = json;
   }

   public String getData() {
     return this.data;
   }

   public void setData(String data) {
     this.data = data;
   }

   public String getNext() {
     return this.next;
   }

   public void setNext(String next) {
     this.next = next;
   }
 }

/* Location:           E:\ruixin-core.jar
 * Qualified Name:     net.ruixin.web.struts2.plugins.AjaxDataResultType
 * JD-Core Version:    0.5.4
 */